#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/9/3 15:10
# @Author : 吴敬超
# explain:
import pandas as pd
import threading
import numpy as np
import netCDF4 as nc
import datetime
import csv
import time as ti
import glob
import multiprocessing
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
file_path = 'D:/ehlocean/data/TEMPSALT/B.E.13.B1850C5.ne120_t12.sehires38.003.sunway_02.rtm.h0.0022-02.nc'
outfile="D:/fiecsv/test.csv"
# file_path = 'D:\NetCDFfile\盐度三个月经纬度均匀处理后数据\SALT_B.E.13.B1850C5.ne120_t12.sehires38.003.sunway_02.pop.h.0021-01.nc'
nc = nc.Dataset(file_path)
#
print(nc.variables.keys())


for var in nc.variables.keys():
    data=nc.variables[var][:].data
    print "************"
    print(var,data.shape)
    print(var)
    print(data.shape)
# time = nc.variables['time'][:]
#
# lat = nc.variables['lat'][:]
# lon = nc.variables['lon'][:]
#
# listvariables = []
# listvariables.append(time)
# listvariables.append(lat)
# listvariables.append(lon)
#
# # print listvariables
# # QCHANR1 = nc.variables['QCHANR'][:]
#
# QCHANR1 = nc.variables['QCHANR'][:, 10:14, 30:34]
#
# print len(QCHANR1[0])

#
# print type(time)
# print type(lat)
# print type(lon)
#
# print type(QCHANR1)
#
# print type(QCHANR1[0][0])
# if type(QCHANR1) == np.ma.core.MaskedArray:
#     print "9999999"
# if isinstance(QCHANR1, np.ma.core.MaskedArray):
#     print "9999999"
#
# print("change weidu num  is ", QCHANR1.ndim)
# if QCHANR1.ndim == 3:
#     print ("**************")

#
# #
#
# for i, val in enumerate(QCHANR1):
#     print ("序号：%s   值：%s" % (i + 1, val.ndim))


# def bianli(lists):
#     for i, val in enumerate(lists):
#
#         if val.ndim==0:
#             break
#         # print ("i is",i)
#         #
#         #
#         # print("change weidu num  is ", val.ndim)
#
#         # if isinstance(QCHANR1, np.ma.core.MaskedArray):
#         #     print ("递归没有到底")
#         #     bianli(val)
#         # else:
#         #     print ("递归到底")
#         print ("序号：%s   值：%s" % (i, val.ndim))
#
#         if type(val) != np.ma.core.MaskedArray:
#             print "递归到底"
#
#             # yuansu.append(i)
#         else:
#             print "递归没有到底"
#             bianli(val)

#
#
# def tocsv(outpath,vlsit,csvheadlist,rlist):
#
#     print "***tocsv****"
#
#
#
#     dict = {}
#








#
#
#
# res = []
# def bianli(lists, result):
#     for i, val in enumerate(lists):
#
#         print ("val ndim is ", val.ndim)
#         r = []
#         r.extend(result)
#         r.append(i)
#         # print (r)
#
#         if val.ndim == 1:
#             print ("******rrrrrrr*******", r)
#             continue
#             # break
#         if type(val) != np.ma.core.MaskedArray:
#             print "递归到底"
#
#             # yuansu.append(i)
#         else:
#             print "递归没有到底"
#             bianli(val, r)
#
#
# bianli(QCHANR1, res)

# QCHANRarr = np.array(QCHANR)
# np.savetxt('name.csv',QCHANRarr,delimiter = ',')
#

#
# print QCHANR
#
# print "***************QCHANRkey*****************************"
# QCHANRkey=nc.variables['QCHANR'].keys()
# print QCHANRkey

#
# nctime = file_obj.variables['time']
#
# times = nc.num2date(nctime[:], nctime.units)
# print len(times)
# print "+++is"+str(times[0].strftime("%Y-%m-%d %H:%M:%S"))
